// +---------------------------------------------------------------------------+
// | Copyright (c) 2014-2015.                                                  |
// | Website: http://www.mamahaocai.com/                                       |
// | Author : David 黎 <lovedavid2046@163.com>                                 |
// +---------------------------------------------------------------------------+
/**
 * 登录验证
 */
function check_login(){
    var reg_p=/^(13[0-9]|15[0|1|2|3|6|7|8|9]|18[0|2|3|5|6|7|8|9]|17[0])\d{8}$/;
    var reg_e=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var username=document.getElementById('username').value;
    var password=document.getElementById('password').value;
    var result=document.getElementById("result");
    var messages=document.getElementById("messages");
    var res_p=username.match(reg_p);
    var res_e=username.match(reg_e);
    var next;

    //判断复选框是否被选中
    if ($("#next").is(":checked")) {
        next = 'week';
    }
    if(res_p || res_e){
        $.post("<?php echo U('/loginCheck');?>",{username:username,password:password,week:next},function(msg){
            if(msg=="1"){
                messages.innerHTML="请填写正确的手机或邮箱格式。";
                result.style.display="block";
            }else if(msg=="2"){
                messages.innerHTML="您输入的密码和账号不匹配，请重新输入。";
                result.style.display="block";
            }else if(msg=="3"){
                messages.innerHTML="该手机号未注册。";
                result.style.display="block";
            }else if(msg=="4"){
                messages.innerHTML="该邮箱未注册。";
                result.style.display="block";
            }else if(msg=="0"){
                result.style.display="none";
                if(result.style.display=="none"){
                    window.location.href="<?php echo U('/index');?>";
                }else{
                    messages.innerHTML="错误信息未处理完成。";
                    result.style.display="block";
                }
            }else{
                alert(msg);
            }
        });
    }else{
        messages.innerHTML="请填写正确的账号格式。";
        result.style.display="block";
    }
}
